package com.luli.dao;

import com.luli.pojo.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;
import java.sql.ResultSet;
import java.util.List;

/**
 * 陆离
 * 2024/10/10 18:08:06
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:spring.xml")
public class Test2 {
    @Resource
    private JdbcTemplate template;
    @Test
    public void testLiftCircle(){
// template.execute("insert into user values(100,'aa','bbb')");
//这玩意就是建立映射关系，避免不了，这里是测试，实际上还是新建一个类好。
        RowMapper<User> rowMapper = (ResultSet resultSet, int i) -> {
            User user = new User();
            user.setId(resultSet.getInt("id"));
            user.setUserName(resultSet.getString("username"));
            user.setPassWord(resultSet.getString("password"));
            return user;
        };
        List<User> query = template.query("select * from user1", rowMapper);
        System.out.println(query);
    }
}
